import java.util.Stack;

public class Q1 {
    private Stack<Integer> s1;
    private Stack<Integer> s2;
    /** initialize your data structure here. */
    public Q1() {
        s1 = new Stack<Integer>();
        s2 = new Stack<Integer>();
    }

    public void push(int x) {
        if(s2.isEmpty() || x <= s2.peek()){
            s2.push(x);
        }
        s1.push(x);
    }

    public void pop() {
        if(s1.peek() == s2.peek()){
            s1.pop();
            s2.pop();
        }
        else{
            s1.pop();
        }
    }

    public int top() {
        return s1.peek();
    }

    public int min() {
        return s2.peek();
    }

    public static void main(String[] args) {
        Q1 two = new Q1();
        two.push(512);
        two.push(-1024);
        two.push(-1024);
        two.push(512);

        two.pop();
        int min = two.min();
        System.out.println(min);
        two.pop();
        int min2 = two.min();
        System.out.println(min2);
        two.pop();
        int min3 = two.min();
        System.out.println(min3);
    }
}
